package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.dto.EmployeeDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auth: cdz
 * @Desc: 菜品分类
 * @Date: 2023/3/3 21:44
 */
@RestController
@RequestMapping("/admin/category")
@Slf4j
@Api(tags = "菜品分类接口")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 功能描述: 类型分页
     *
     * @return : com.sky.result.Result<com.sky.result.PageResult>
     */
    @ApiOperation("菜品分类分页")
    @GetMapping("/page")
    public Result<PageResult> page(@ApiParam("菜品类型DTO") CategoryPageQueryDTO categoryPageQueryDTO) {
        PageResult pageResult = categoryService.page(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 功能描述:  新增类型
     *
     * @return : com.sky.result.Result
     */
    @ApiOperation("新增菜品")
    @PostMapping
    public Result save(@ApiParam("新增分类DTO") @RequestBody CategoryDTO categoryDTO) {
        boolean flag = categoryService.save(categoryDTO);
        return flag ? Result.success() : Result.error("新增失败");
    }

    /**
     * 功能描述: 类型启用,禁用
     *
     * @return : com.sky.result.Result
     */
    @ApiOperation("类型禁用,启用")
    @PostMapping("/status/{status}")
    public Result enableOrDisable(@ApiParam("类型") @PathVariable int status, Long id) {
        boolean flag = categoryService.enableOrDisable(status, id);
        return flag ? Result.success() : Result.error("修改失败");
    }

    /**
     * 功能描述: 分类修改
     *
     * @return : com.sky.result.Result
     */
    @ApiOperation("分类修改")
    @PutMapping
    public Result update(@ApiParam("分类修改DTO") @RequestBody CategoryDTO categoryDTO) {
        System.out.println(categoryDTO);
        boolean flag = categoryService.update(categoryDTO);
        return flag ? Result.success() : Result.error("修改失败");
    }

    /**
     * 功能描述: 根据id删除
     * @return : com.sky.result.Result
     */
    @ApiOperation("根据id删除类型")
    @DeleteMapping
    public Result delete(@ApiParam("删除id") Long id) {
        boolean flag = categoryService.delete(id);
        return flag ? Result.success() : Result.error("删除失败");
    }

    /**
     * 功能描述: 根据类型查询分类
     * @return : com.sky.result.Result<List<Category>>
     */
    @GetMapping("/list")
    @ApiOperation("根据类型查询分类")
    public Result<List<Category>> list(Integer type){
        List<Category> list = categoryService.list(type);
        return Result.success(list);
    }
}
